//
//  SchoolVC.swift
//  LeGou
//
//  Created by 刘亿前 on 2022/10/14.
//

import UIKit
import LTScrollView

class SchoolVC: ZMViewController {

    private lazy var layout: LTLayout = {
        let layout = LTLayout()
        layout.titleViewBgColor = UIColor(r: 255, g: 255, b: 255)
        layout.titleSelectColor = UIColor(r: 222, g: 63, b: 38)
        layout.bottomLineColor = UIColor(r: 222, g: 63, b: 38)
        layout.titleColor = UIColor(r: 0, g: 0, b: 0)
//        layout.pageBottomLineColor = .clear
        layout.lrMargin = 12
        layout.sliderWidth = 16
        layout.titleMargin = 24
        layout.isNeedScale = false
        layout.titleFont = UIFont.zm.fontMedium(size: 16)
        layout.showsHorizontalScrollIndicator = false
        return layout
    }()
        
    private lazy var controllers: [SchoolListVC] = {
        var arr = [SchoolListVC]()
        cateArr.forEach { val in
            let vc = SchoolListVC()
            vc.cid = val.cid
            arr.append(vc)
        }
        return arr
    }()
    
    private lazy var advancedManager: LTAdvancedManager = {
        let manager = LTAdvancedManager(frame: SCREEN_BOUNDS, viewControllers: controllers, titles: cateArr.map{return $0.cname}, currentViewController: self, layout: layout, headerViewHandle: {
            return UIView()
        })
        manager.backgroundColor = .clear
        return manager
    }()
    
    var cateArr = [SchoolCategoryModel]()

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "商学院"
        requestCategory()
    }
}

// MARK: - Request Action
extension SchoolVC {
    func requestCategory() {
        ZMToast.showActivity()
        SchoolAPI.school_cate.rxRequestNullAble(type: [SchoolCategoryModel].self).subscribe(onNext:{ [unowned self] resp in
            ZMToast.hiddenActivity()
            if let data = resp {
                self.cateArr = data
            }
            let all = SchoolCategoryModel(cname: "全部", cid: 0)
            self.cateArr.insert(all, at: 0)
            self.view.addSubview(self.advancedManager)
        }).disposed(by: disposeBag)
    }
}
